
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _extends2 = _interopRequireDefault(require('@babel/runtime/helpers/extends'));

const _utils = require('../utils');

const _router = require('../utils/router');

const _relation = require('../mixins/relation');

const _button = _interopRequireDefault(require('../button'));

const _createNamespace = (0, _utils.createNamespace)('goods-action-button');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

const _default = createComponent({
  mixins: [(0, _relation.ChildrenMixin)('vanGoodsAction')],
  props: (0, _extends2.default)({}, _router.routeProps, {
    type: String,
    text: String,
    icon: String,
    color: String,
    loading: Boolean,
    disabled: Boolean,
  }),
  computed: {
    isFirst: function isFirst() {
      const prev = this.parent && this.parent.children[this.index - 1];
      return !prev || prev.$options.name !== this.$options.name;
    },
    isLast: function isLast() {
      const next = this.parent && this.parent.children[this.index + 1];
      return !next || next.$options.name !== this.$options.name;
    },
  },
  methods: {
    onClick: function onClick(event) {
      this.$emit('click', event);
      (0, _router.route)(this.$router, this);
    },
  },
  render: function render() {
    const h = arguments[0];
    return h(_button.default, {
      class: bem([{
        first: this.isFirst,
        last: this.isLast,
      }, this.type]),
      attrs: {
        square: true,
        size: 'large',
        type: this.type,
        icon: this.icon,
        color: this.color,
        loading: this.loading,
        disabled: this.disabled,
      },
      on: {
        click: this.onClick,
      },
    }, [this.slots() || this.text]);
  },
});

exports.default = _default;
